namespace STD.Shared.Infrastructure.Messaging;

/// <summary>
/// 消息总线接口
/// </summary>
public interface IMessageBus
{
    /// <summary>
    /// 发布消息
    /// </summary>
    /// <typeparam name="T">消息类型</typeparam>
    /// <param name="message">消息</param>
    /// <param name="routingKey">路由键</param>
    /// <returns>是否成功</returns>
    Task<bool> PublishAsync<T>(T message, string routingKey);
    
    /// <summary>
    /// 订阅消息
    /// </summary>
    /// <typeparam name="T">消息类型</typeparam>
    /// <param name="routingKey">路由键</param>
    /// <param name="handler">消息处理器</param>
    /// <returns>订阅ID</returns>
    Task<string> SubscribeAsync<T>(string routingKey, Func<T, Task> handler);
    
    /// <summary>
    /// 取消订阅
    /// </summary>
    /// <param name="subscriptionId">订阅ID</param>
    /// <returns>是否成功</returns>
    Task<bool> UnsubscribeAsync(string subscriptionId);
    
    /// <summary>
    /// 发送消息到队列
    /// </summary>
    /// <typeparam name="T">消息类型</typeparam>
    /// <param name="message">消息</param>
    /// <param name="queueName">队列名称</param>
    /// <returns>是否成功</returns>
    Task<bool> SendToQueueAsync<T>(T message, string queueName);
    
    /// <summary>
    /// 从队列接收消息
    /// </summary>
    /// <typeparam name="T">消息类型</typeparam>
    /// <param name="queueName">队列名称</param>
    /// <param name="handler">消息处理器</param>
    /// <returns>订阅ID</returns>
    Task<string> ReceiveFromQueueAsync<T>(string queueName, Func<T, Task> handler);
} 